package gen.tools.query;

import gen.tools.Widgets;
import gen.tools.structures.ModNode;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

public class QueryModDownStream extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public QueryModDownStream() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		final Widgets wid = new Widgets();
		request.setCharacterEncoding( wid.UIcodeSet );
		response.setCharacterEncoding( wid.UIcodeSet );
		response.setContentType("application/json");
		
		final String modId = request.getParameter("modId");
		final String urlStr = wid.JENKINSURL+"job/"+modId+"/config.xml";
		
		
		ArrayList<ModNode> mns = new ArrayList<ModNode>();
		
		try {
			mns=wid.getModBEdependency(modId,false,false,urlStr,wid.JENKINS_USR, wid.JENKINS_PWD);	
		} catch (Exception e) {
			wid.errLog(e);
		}
		
		response.getWriter().write( new Gson().toJson(mns) );
		
	}
}
